using UnityEngine;

public class ChangeTeamDragListener : MonoBehaviour
{
	public Rect rect = new Rect(0f, 50f, 800f, 350f);

	public float dragDistance;

	private Vector2 dragDownPos;

	private Vector2 dragUpPos;

	private bool isUse;

	private void Awake()
	{
		MyScreen.init();
	}

	private void Start()
	{
		rect = new Rect(0f, 50f * ((float)Screen.height / 480f), Screen.width, 350f * ((float)Screen.height / 480f));
		dragDistance *= (float)Screen.width / 800f;
	}

	private void OnDragStart()
	{
		if (Global.isAndroid)
		{
			dragDownPos = UnityEngine.Input.GetTouch(0).position;
		}
		else
		{
			dragDownPos = UnityEngine.Input.mousePosition;
		}
		isUse = false;
	}

	private void OnDrag(Vector2 delta)
	{
		if (Global.isAndroid)
		{
			dragUpPos = UnityEngine.Input.GetTouch(0).position;
		}
		else
		{
			dragUpPos = UnityEngine.Input.mousePosition;
		}
		if (MathHelper.isInRect(rect, dragDownPos) && MathHelper.isInRect(rect, dragUpPos) && !isUse)
		{
			if (dragUpPos.x - dragDownPos.x > dragDistance)
			{
				ToRight();
				isUse = true;
			}
			else if (dragDownPos.x - dragUpPos.x > dragDistance)
			{
				ToLeft();
				isUse = true;
			}
		}
	}

	public void ToRight()
	{
		if (!GameData.IsFinishTutorial)
		{
			return;
		}
		if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex == 2)
		{
			if (dragDownPos.x < (float)Screen.width * 0.5f)
			{
				Instance<UIChooseTeam>.instance.changeLogoTowardRight(TeamType.USER);
			}
			else if (dragDownPos.x > (float)Screen.width * 0.5f)
			{
				Instance<UIChooseTeam>.instance.changeLogoTowardRight(TeamType.COMPUTER);
			}
		}
		else if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex == 8)
		{
			Instance<UIChooseLevel>.instance.ToRight();
		}
		else if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex == 5)
		{
			Instance<UIChooseMode>.instance.ToRight();
		}
	}

	public void ToLeft()
	{
		if (!GameData.IsFinishTutorial)
		{
			return;
		}
		if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex == 2)
		{
			if (dragDownPos.x < (float)Screen.width * 0.5f)
			{
				Instance<UIChooseTeam>.instance.changeLogoTowardLeft(TeamType.USER);
			}
			else if (dragDownPos.x > (float)Screen.width * 0.5f)
			{
				Instance<UIChooseTeam>.instance.changeLogoTowardLeft(TeamType.COMPUTER);
			}
		}
		else if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex == 5)
		{
			Instance<UIChooseMode>.instance.ToLeft();
		}
		else if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex == 8)
		{
			Instance<UIChooseLevel>.instance.ToLeft();
		}
	}
}
